//
//  UIBarButton+extension.swift
//  微博
//
//  Created by liuerying on 16/5/20.
//  Copyright © 2016年 liuerying. All rights reserved.

//封装自定义导航条的按钮

import UIKit


extension UIBarButtonItem{

    convenience init(imageName: String? = nil,title: String? = nil ,target: AnyObject?, action: Selector) {
        self.init()
        
        let btn = UIButton()
        
        if let img = imageName{
        
            btn.setImage(UIImage(named: img), forState: UIControlState.Normal)
            
            btn.setImage(UIImage(named: img + "_highlighted"), forState: .Highlighted)
            
            
        }
        
        
        btn.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        btn.setTitle(title, forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Highlighted)
        
        //自适应大小
        btn.sizeToFit()
        
        self.customView = btn
        
    }
}